package imnu.work.imnu0713_work01;

import java.util.Scanner;

public class Test_01 {
    //给定一个0～1000的整数，求各位数的和，例如345的结果是3+4+5＝12注：分解数字既可以先除后模也可以先模后除
    public static void main(String[] args) {
        System.out.println("请输入一个整数（1~1000）:");
        while(true) {
            Scanner sc = new Scanner(System.in);
            int num = sc.nextInt();
            int a = 0, b = 0, c = 0, d = 0, sum = 0;
            a = num % 10;
            b = num / 10 % 10;
            c = num / 100 % 10;
            d = num / 1000;
            sum = a + b + c + d;
            System.out.println("各个位的和为：" + sum);
        }

    }

}
